<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for components/UploadExcel/index.vue</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../prettify.css" />
    <link rel="stylesheet" href="../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../index.html">All files</a> / <a href="index.html">components/UploadExcel</a> index.vue
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/66</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/22</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/11</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/65</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">&lt;template&gt;
  &lt;div&gt;
    &lt;input
      ref="excel-upload-input"
      class="excel-upload-input"
      type="file"
      accept=".xlsx, .xls"
      @change="handleClick"
    &gt;
    &lt;div
      class="drop"
      @drop="handleDrop"
      @dragover="handleDragover"
      @dragenter="handleDragover"
    &gt;
      Drop excel file here or
      &lt;el-button
        :loading="loading"
        style="margin-left:16px;"
        size="mini"
        type="primary"
        @click="handleUpload"
      &gt;
        Browse
      &lt;/el-button&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/template&gt;
&nbsp;
&lt;script lang="ts"&gt;
<span class="cstat-no" title="statement not covered" >import { Component, Prop, Vue } from 'vue-property-decorator'</span>
<span class="cstat-no" title="statement not covered" >import XLSX from 'xlsx'</span>
&nbsp;
<span class="fstat-no" title="function not covered" >@Component({</span>
  name: 'UploadExcel'
})
<span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" >export default class extends Vue {</span></span>
<span class="cstat-no" title="statement not covered" >  @Prop({ required: true }) private beforeUpload!: Function</span>
<span class="cstat-no" title="statement not covered" >  @Prop({ required: true }) private onSuccess!: Function</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >  private loading = false</span>
<span class="cstat-no" title="statement not covered" >  private excelData = {</span>
    header: null,
    results: null
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private generateData(header: any, results: any) {</span>
<span class="cstat-no" title="statement not covered" >    this.excelData.header = header</span>
<span class="cstat-no" title="statement not covered" >    this.excelData.results = results</span>
<span class="cstat-no" title="statement not covered" >    this.onSuccess &amp;&amp; this.onSuccess(this.excelData)</span>
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private handleDrop(e: DragEvent) {</span>
<span class="cstat-no" title="statement not covered" >    e.stopPropagation()</span>
<span class="cstat-no" title="statement not covered" >    e.preventDefault()</span>
<span class="cstat-no" title="statement not covered" >    if (this.loading) return</span>
<span class="cstat-no" title="statement not covered" >    if (!e.dataTransfer) return</span>
<span class="cstat-no" title="statement not covered" >    const files = e.dataTransfer.files</span>
<span class="cstat-no" title="statement not covered" >    if (files.length !== 1) {</span>
<span class="cstat-no" title="statement not covered" >      this.$message.error('Only support uploading one file!')</span>
<span class="cstat-no" title="statement not covered" >      return</span>
    }
<span class="cstat-no" title="statement not covered" >    const rawFile = files[0] // only use files[0]</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >    if (!this.isExcel(rawFile)) {</span>
<span class="cstat-no" title="statement not covered" >      this.$message.error('Only supports upload .xlsx, .xls, .csv suffix files')</span>
<span class="cstat-no" title="statement not covered" >      return false</span>
    }
<span class="cstat-no" title="statement not covered" >    this.upload(rawFile)</span>
<span class="cstat-no" title="statement not covered" >    e.stopPropagation()</span>
<span class="cstat-no" title="statement not covered" >    e.preventDefault()</span>
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private handleDragover(e: DragEvent) {</span>
<span class="cstat-no" title="statement not covered" >    e.stopPropagation()</span>
<span class="cstat-no" title="statement not covered" >    e.preventDefault()</span>
<span class="cstat-no" title="statement not covered" >    if (e.dataTransfer) {</span>
<span class="cstat-no" title="statement not covered" >      e.dataTransfer.dropEffect = 'copy'</span>
    }
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private handleUpload() {</span>
<span class="cstat-no" title="statement not covered" >    (this.$refs['excel-upload-input'] as HTMLInputElement).click()</span>
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private handleClick(e: MouseEvent) {</span>
<span class="cstat-no" title="statement not covered" >    const files = (e.target as HTMLInputElement).files</span>
<span class="cstat-no" title="statement not covered" >    if (files) {</span>
<span class="cstat-no" title="statement not covered" >      const rawFile = files[0] // only use files[0]</span>
<span class="cstat-no" title="statement not covered" >      this.upload(rawFile)</span>
    }
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private upload(rawFile: File) {</span>
<span class="cstat-no" title="statement not covered" >    (this.$refs['excel-upload-input'] as HTMLInputElement).value = '' // Fixes can't select the same excel</span>
<span class="cstat-no" title="statement not covered" >    if (!this.beforeUpload) {</span>
<span class="cstat-no" title="statement not covered" >      this.readerData(rawFile)</span>
<span class="cstat-no" title="statement not covered" >      return</span>
    }
<span class="cstat-no" title="statement not covered" >    const before = this.beforeUpload(rawFile)</span>
<span class="cstat-no" title="statement not covered" >    if (before) {</span>
<span class="cstat-no" title="statement not covered" >      this.readerData(rawFile)</span>
    }
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private readerData(rawFile: File) {</span>
<span class="cstat-no" title="statement not covered" >    this.loading = true</span>
<span class="cstat-no" title="statement not covered" >    const reader = new FileReader()</span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    reader.onload = e =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >      const data = (e.target as FileReader).result</span>
<span class="cstat-no" title="statement not covered" >      const workbook = XLSX.read(data, { type: 'array' })</span>
<span class="cstat-no" title="statement not covered" >      const firstSheetName = workbook.SheetNames[0]</span>
<span class="cstat-no" title="statement not covered" >      const worksheet = workbook.Sheets[firstSheetName]</span>
<span class="cstat-no" title="statement not covered" >      const header = this.getHeaderRow(worksheet)</span>
<span class="cstat-no" title="statement not covered" >      const results = XLSX.utils.sheet_to_json(worksheet)</span>
<span class="cstat-no" title="statement not covered" >      this.generateData(header, results)</span>
<span class="cstat-no" title="statement not covered" >      this.loading = false</span>
    }
<span class="cstat-no" title="statement not covered" >    reader.readAsArrayBuffer(rawFile)</span>
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private getHeaderRow(sheet: { [key: string ]: any }) {</span>
<span class="cstat-no" title="statement not covered" >    const headers: string[] = []</span>
<span class="cstat-no" title="statement not covered" >    const range = XLSX.utils.decode_range(sheet['!ref'])</span>
<span class="cstat-no" title="statement not covered" >    const R = range.s.r</span>
    // start in the first row
<span class="cstat-no" title="statement not covered" >    for (let C = range.s.c; C &lt;= range.e.c; ++C) { // walk every column in the range</span>
<span class="cstat-no" title="statement not covered" >      const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })]</span>
      // find the cell in the first row
<span class="cstat-no" title="statement not covered" >      let hdr: string = ''</span>
<span class="cstat-no" title="statement not covered" >      if (cell &amp;&amp; cell.t) hdr = XLSX.utils.format_cell(cell)</span>
<span class="cstat-no" title="statement not covered" >      if (hdr === '') {</span>
<span class="cstat-no" title="statement not covered" >        hdr = 'UNKNOWN ' + C // replace with your desired default</span>
      }
<span class="cstat-no" title="statement not covered" >      headers.push(hdr)</span>
    }
<span class="cstat-no" title="statement not covered" >    return headers</span>
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private isExcel(file: File) {</span>
<span class="cstat-no" title="statement not covered" >    return /\.(xlsx|xls|csv)$/.test(file.name)</span>
  }
}
&lt;/script&gt;
&nbsp;
&lt;style lang="scss" scoped&gt;
.excel-upload-input {
  display: none;
  z-index: -9999;
}
&nbsp;
.drop {
  border: 2px dashed #bbb;
  width: 600px;
  height: 160px;
  line-height: 160px;
  margin: 0 auto;
  font-size: 24px;
  border-radius: 5px;
  text-align: center;
  color: #bbb;
  position: relative;
}
&lt;/style&gt;
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Aug 05 2019 17:01:25 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../sorter.js"></script>
</body>
</html>
